<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://www.yaodian100.com/jsp/yaodian100" prefix="yaodian100" %>
<%@ include file="/taglibs.jsp"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>'/>

<script src="/js/grid.locale-en.js" type="text/javascript"></script>
<script src="/js/jquery.jqGrid.min.js" type="text/javascript" charset="UTF-8"></script>
<script src="/js/jquery.cascade.ext.js" type="text/javascript" charset="UTF-8"></script>
<script src="/js/jquery.cascade.js" type="text/javascript" charset="UTF-8"></script>
<script src="/js/jquery.templating.js" type="text/javascript" charset="UTF-8"></script>
<script src="/js/jquery.alphanumeric.js" type="text/javascript" charset="UTF-8"></script>
<script src="/js/jquery.form.js" type="text/javascript" charset="UTF-8"></script>
<link href="/css/ui.jqgrid.css" rel="stylesheet" type="text/css" media="screen" />
<link href="/css/validator.css" rel="stylesheet" type="text/css"/>
<link href="/css/ui.jqgrid.css" rel="stylesheet" type="text/css" media="screen" />
<link href="/css/ddaccordion.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript">
var content;
$().ready( function() {
	$("#sort_${prodSortBy}").addClass("${prodSortByType}");
	<c:if test="${not empty paramCategoryL1}">
	$("#paramCategoryL1").change();	
	</c:if>
	<c:if test="${not empty paramCategoryL2}">	
	resetCategory(3, "${paramCategoryL2}");	
	</c:if>
	<c:if test="${not empty paramCategoryL3}">
	resetCategory(4, "${paramCategoryL3}");
	</c:if>	
	//$.each($("#paramProductIsScm").find('option'), function(index, opt) {
	//	if(opt.value == 'N') {
	//		opt.disabled = true;
	//	}
	//});
	
	//$.each($("#paramProductType").find('option'), function(index, opt) {
	//	if(!(opt.value == '' || opt.value == '0' || opt.value == '1')) {
	//		opt.disabled = true;
	//	}
	//});
	$("#getSupplier").click(function() {
		//qry_target = 'member';
		doAR('<s:url value="/json/supplierPops.do"/>', 'dialog'); 
		openDialog('供应商搜寻',content, 550, 440);
	});	 
	$("#getBrand").click(function() {
		doAR('<s:url value="/json/brandPops.do"/>', 'dialog'); 
		openDialog('品牌搜寻',content, 550, 440);
	});
});
function sort(sortBy,en) {
	var formObj = document.forms[0];
	formObj.prodSortByEntity.value = en;
	
	//alert(formObj.prodSortBy.value+" "+formObj.prodSortByType.value+",new:"+sortBy);
	if(sortBy == formObj.prodSortBy.value) {
		if(formObj.prodSortByType.value == 'desc')
			formObj.prodSortByType.value = 'asc';
		else
			formObj.prodSortByType.value = 'desc';
	} else {
		formObj.prodSortBy.value = sortBy;
	}	
	formObj.submit();
}
function resetCategory(level, categoryId) {
	for(var c=4;c>=level;c--) {
		$("#paramCategoryL"+c).find('option').remove().end();
		$("#paramCategoryL"+c).append('<option value="">--请选择--</option>');
	}
	$("#paramCategoryL"+level).find('option').remove().end();
	
	$("#paramCategoryL"+level).append('<option value="">--请选择--</option>');
	//alert(level+"/"+categoryId);
	$.getJSON('<s:url value="/json/categoryChild.do"/>', 
	        {id: categoryId},
	        function(json) {
	        	//alert(json.objList);
	        	$.each(json.objList, function(key, val) {
	        		//alert(key+"/"+val);
	        		$("#paramCategoryL"+level).append('<option value="'+val.id+'">'+val.name+'</option>');
	        	  });
	        	<c:if test="${not empty paramCategoryL2}">
	        	if(level==2){
	        	$("#paramCategoryL2").val("${paramCategoryL2}");
	        	}
	        	</c:if>
	        	<c:if test="${not empty paramCategoryL3}">
	        	if(level==3){
	        	$("#paramCategoryL3").val("${paramCategoryL3}");
	        	}
	        	</c:if>
	        	<c:if test="${not empty paramCategoryL4}">
	        	if(level==4){
	        	$("#paramCategoryL4").val("${paramCategoryL4}");
	        	}
	        	</c:if>
	        });
}
function selectAll() {
	size1 = $(':check[name^="paramSelectArray"]').length;
	size2 = $('input:checked[name^="paramSelectArray"]').length;
	//alert('all:'+size1+",checked:"+size2);
	count = parseInt($("#selectSize").text());
	$("#selectSize").text(count+size1-size2);

	$(':check[name^="paramSelectArray"]').attr("checked", "checked");
}
function selectNone() {
	try {
		size = $('input:checked[name^="paramSelectArray"]').length;

		count = parseInt($("#selectSize").text());
		$("#selectSize").text(count-parseInt(size));
	} catch (e) {
		alert(e);
	}
	$(':check[name^="paramSelectArray"]').removeAttr("checked");
}

function changeSelectSize(checkbox) {
	count = parseInt($("#selectSize").text());
	if(checkbox.checked == true) {
		$("#selectSize").text(count+1);
	} else {
		$("#selectSize").text(count-1);
	}
}

</script>
<s:actionerror cssClass="errmsg"/>
<s:actionmessage cssClass="errmsg"/>
  <h1>查寻商品 - 批次新增上架檔</h1>
  <div class="batchstep">
    <div class="batchstep-1">
      <span class="onstep1">Step 1：查寻商品/选取商品</span>
      <span class="step2">Step 2：编辑资料</span>
      <span class="step3">Step 3：核对资料/完成编辑</span>
    </div>
  </div>

      <s:form action="changePage.do">
      	<s:hidden name="prodSortBy"/> <s:hidden name="prodSortByType"/> <s:hidden name="prodSortByEntity"/>
      	<input type="hidden" name="joinSelect" value="${joinSelect}">
        <div class="searchform">
  		  <div class="formrow"><label for="productIdParam">商品编号：</label><span>
  		  <s:textarea name="paramProductId" id="productIdParam" title="商品编号"/></textarea></span></div>
  		  <div class="formrow"><label for="productNameParam">商品名称：</label><span>
  		  <s:textfield title="商品名称" name="paramProductName"/></span></div>
          <div class="formrow">
			<label for="scmParam">采购模式：</label>
          	<span>
          	<s:select name="paramProductIsScm" id="paramProductIsScm" list="menuProductIsScm.options" listKey="key" listValue="value.name" headerKey="" headerValue="全部"/>
            </span>
            <label for="productTypeParam">商品型态：</label>
            <span>
            <s:select name="paramProductType" id="paramProductType"  list="menuProductType.options" listKey="key" listValue="value.name" headerKey="" headerValue="全部"/>
            </span>
            <label for="list_do_productAttributeParam">销售状态：</label>
            <span>
            <s:select name="paramProductAttr" list="menuProductAttr.options" listKey="key" listValue="value.name" headerKey="" headerValue="全部"/>
			</span>
          </div>
          <div class="formrow">
            <label for="supplierIdParam">供应商编号：</label><span><input type="text" id="supplierIdParam" value="${paramSupplierId}" maxlength="6" name="paramSupplierId">
            <img id="getSupplier" style="height: 16px; width: 16px; position: relative; display: inline;" src="/images/none.gif" class="ui-icon ui-icon-search"></span>
            <label for="brandIdParam">品牌：</label>
            <span><s:textfield name="paramBrand" id="brandIdParam" />
            <img class="ui-icon ui-icon-search" src="/images/none.gif" style="height:16px; width:16px; position:relative; display:inline;" id="getBrand"/>  
			<input type="text" name="brandName" id="brandName" value="${brandName}" readonly="readonly" size="60" style="border: 0px;"/></span>
          </div>
          <div class="formrow">
            <label for="categorySelect">主分类：</label>
            <span>
            <s:select list="menuCategoryLevel1List" name="paramCategoryL1" id="paramCategoryL1" listKey="id" listValue="name" headerKey="" headerValue="--请选择--" onchange="resetCategory(2, this.value)"></s:select>
			</span>
            <span>
            <s:select list="menuCategoryLevel2List" name="paramCategoryL2" id="paramCategoryL2" listKey="id" listValue="name" headerKey="" headerValue="--请选择--" onchange="resetCategory(3, this.value)"></s:select>
			</span>
            <span>
            <s:select list="menuCategoryLevel3List" name="paramCategoryL3" id="paramCategoryL3" listKey="id" listValue="name" headerKey="" headerValue="--请选择--" onchange="resetCategory(4, this.value)"></s:select>
			</span>
            <span>
            <s:select list="menuCategoryLevel4List" name="paramCategoryL4" id="paramCategoryL4" listKey="id" listValue="name" headerKey="" headerValue="--请选择--"></s:select>
			</span>
          </div>
          <div class="formrow">
            <label for="shelvesStatus">上架中：</label>
            <s:select list="#{'true':'是','false':'否'}" name="paramHasShelf" headerKey="" headerValue="全部"/>
          </div>
          <div class="formrow"><label></label>
          <input type="button" onclick="this.form.action='search.do';this.form.submit();" value="查寻"></div>
        </div>
      <h3 class="tword">查寻结果 - 共${pager.totalSize}笔 (已选择 <span id="selectSize">${selectSize}</span> 笔资料)</h3>
      <div class="seltool">选取：<a href="javascript:;" onclick="document.forms[0].action='selectAll.do';document.forms[0].submit();">全部全选</a>、<a href="javascript:;" onclick="selectAll();">本页全选</a>、<a href="javascript:;" onclick="selectNone();">本页取消</a></div>
	  <table width="100%" class="tb-1">
        <thead>
          <th>#</th>
          <th>商品图</th>
          <th><a href="javascript:;" onclick="sort('productId','p');" id="sort_productId">商品编号</a></th>
          <th><a href="javascript:;" onclick="sort('productName','p');" id="sort_productName">商品名称</a></th>
          <th><a href="javascript:;" onclick="sort('supplierId','p');" id="sort_supplierId">供应商编号</a></th>
          <th><a href="javascript:;" onclick="sort('productBrand','p');" id="sort_productBrand">品牌</a></th>
          <th><a href="javascript:;" onclick="sort('product.mainCategoryID','p');" id="sort_product.mainCategoryID">主分类</a></th>
          <th><a href="javascript:;" onclick="sort('isScm','p');" id="sort_isScm">采购模式</a></th>
          <th><a href="javascript:;" onclick="sort('productType','p');" id="sort_productType">商品型态</a></th>
          <th><a href="javascript:;" onclick="sort('isDelete','p');" id="sort_isDelete">销售状态</a></th>
          <th>上架中</th>
          <th><a href="javascript:;" onclick="sort('promoteName','vs');" id="sort_promoteName">商品促銷小標</a></th>
          <th><a href="javascript:;" onclick="sort('startDate','vs');" id="sort_startDate">上架起始日期时间</a></th>
          <th><a href="javascript:;" onclick="sort('endDate','vs');" id="sort_endDate">上架结束日期时间</a></th>
          <th><a href="javascript:;" onclick="sort('shelfPrice','vs');" id="sort_shelfPrice">上架售价</a></th>
        </thead>
        <tbody>
<s:iterator value="products" var="product" status="rows_index">

<c:set value="${shelfMap[product.productId]}" var="shelf"/>
          <tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">
           <td><s:checkbox name="paramSelectArray['%{#product.productId}']" id="paramSelectArray_%{#product.productId}" onchange="changeSelectSize(this)"/></td>
           <td><yaodian100:productImg productId="${product.productId}" size="75" /></td>
           <td><a href="${midContextPath}/product/edit.do?productId=${product.productId}" target="_blank">${product.productId}</a></td>
           <td style="text-align:left;">${product.productName}</td>
           <td>${product.supplierId}</td>
           <td><c:if test="${!empty menuBrand[product.productBrand]}">${menuBrand[product.productBrand].briefName}</c:if>
           <c:if test="${empty menuBrand[product.productBrand]}">${product.productBrand}</c:if>
           </td>
           <td>${productCategory[product.mainCategoryID]}</td>
           <td>${menuProductIsScm.options[product.isScm].name}</td>
           <td>${menuProductType.options[product.productTypeStr].name}</td>
           <td>${menuProductAttr.options[product.isDelete].name}</td>
           <td><c:if test="${empty shelf}">否</c:if><c:if test="${!empty shelf}">是</c:if></td>
          <td><c:if test="${empty shelf}">-</c:if><c:if test="${!empty shelf}"><c:if test="${fn:trim(shelf.promoteName)==''}">-</c:if><c:if test="${fn:trim(shelf.promoteName)!=''}">${shelf.promoteName}</c:if></c:if></td>
          <td><c:if test="${empty shelf}">-</c:if><c:if test="${!empty shelf}"><fmt:formatDate value="${shelf.startDate}" pattern="yyyy-MM-dd'<br>'HH:mm" /></c:if></td>
          <td><c:if test="${empty shelf}">-</c:if><c:if test="${!empty shelf}"><fmt:formatDate value="${shelf.endDate}" pattern="yyyy-MM-dd'<br>'HH:mm" /></c:if></td>
          <td><c:if test="${empty shelf}">-</c:if><c:if test="${!empty shelf}">${shelf.shelfPrice}</c:if></td>
          </tr>
</s:iterator>
        </tbody>
      </table>
      <yaodian100:pageutilsubmit link="changePage.do" pagerObj="${pager}" />
      <div><input type="button" value="选取完了，开始编辑﹥" name="submit1" class="nstep" onclick="this.form.action='edit.do';this.form.submit();"></div>
      </s:form>
